package cn.itsource.feignclient.fallback;

import cn.itsource.domain.User;
import cn.itsource.feignclient.UserFeignClient;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

@Component // 交给SpringIOC容器管理
public class UserFeignFallbackFactory implements FallbackFactory<UserFeignClient> {

    @Override
    public UserFeignClient create(Throwable throwable) {
        // 工厂方法可以获取异常的信息
        throwable.printStackTrace();
        return new UserFeignClient() {
            @Override
            public User getUser(Long id) {
                return new User(-1l,"FallbackFactory降级","用户服务不可用！");
            }
        };
    }
}
